<?php
declare (strict_types = 1);

namespace app;

use think\App;
use think\facade\Db;
use think\facade\View;
/**
 * 控制器基础类
 */
abstract class AdminBaseController {
    /**
     * Request实例
     * @var \think\Request
     */
    protected $request;

    /**
     * 应用实例
     * @var \think\App
     */
    protected $app;

    /**
     * 控制器中间件
     * @var array
     */
    protected $middleware = [];

    /**
     * 构造方法
     * @access public
     * @param  App  $app  应用对象
     */
    public function __construct(App $app){
        $this->app     = $app;
        $this->request = $this->app->request;

        // 记录访问日志
        $admin = session('admin');
        $log['ip'] = $this->request->ip();
        $log['method'] = $this->request->method();
        $log['url'] = $this->request->url();
        $log['request_time'] = date('Y-m-d H:i:s',$this->request->time());
        $log['admin_id'] = $admin['admin_id']??0;
        $log['user_agent'] = $this->request->header('user-agent');
        $log['params'] = json_encode([]);
        $log['create_time'] = date('Y-m-d H:i:s',time());
        $logId = Db::table('c_app_logs')->insertGetId($log);

        // 控制器初始化
        $this->initialize();
    }

    // 初始化
    protected function initialize(){

    }

}